<template>
  <div class="bodyBox">
    <FrameStyle>
      <!-- 面包屑 -->
      <Breadcrumb :breadName="`留言板管理`" slot="breadcrumb" />
      <!-- 搜索框 -->
      <el-input slot="search">
        <el-button class="el-icon-search" slot="append"></el-button>
      </el-input>
      <!-- 添加按钮 -->
      <!-- <el-button type="primary" slot="addBtn">添加留言</el-button> -->
      <!-- 表格列表 -->
      <el-table :data="tableData" stripe slot="tableList" height="370px">
        <el-table-column label="创建时间" prop="createTime" width="120px">
        </el-table-column>
        <el-table-column prop="username" label="用户姓名"></el-table-column>
        <el-table-column
          prop="content"
          label="留言内容"
          width="180px"
        ></el-table-column>
        <el-table-column label="留言图片" prop="picture" width="auto">
          <template slot-scope="scope">
            <img :src="scope.row.picture" height="50px" />
          </template>
        </el-table-column>
        <el-table-column prop="reply" label="回复内容" width="auto">
        </el-table-column>
        <el-table-column prop="replyPicture" label="回复图片" width="auto">
          <template slot-scope="scope">
            <img :src="scope.row.replyPicture" height="50px" />
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <!-- <el-button size="mini">修改</el-button> -->
            <el-button
              type="danger"
              size="mini"
              @click="delMsgboard(scope.row.id)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页器 -->
      <Pagination
        slot="pageSlot"
        :pageNo="pageNum"
        :pageSize="pageSize"
        :totalRows="totalRows"
        @pageChange="pageChange"
      />
    </FrameStyle>
  </div>
</template>

<script>
import { reqLiuYanBanList,  reqDelData } from "../../../api";
export default {
  data() {
    return {
      tableData: [],
      pageNum: 1,
      pageSize: 10,
      totalRows: 1,
      addForm: {},
      changeForm: {},
      addDiaLogVisible: false,
      changeDiaLogVisible: false,
    };
  },
  created() {
    this.getData();
  },
  methods: {
    //获取留言板数据
    async getData() {
      let { pageNum, pageSize } = this;
      let result = await reqLiuYanBanList({ pageNum, pageSize });
      if (result.code != 200) return false;
      result.data.list.forEach((item) => {
        item.createTime = this.$format(item.createTime);
      });
      this.tableData = result.data.list;
      this.totalRows = result.data.total;
    },
    //删除留言
    async delMsgboard(id) {
      let result = await reqDelData("/msgboard/delete", id);
      if (result.code != 200) return this.$message.error("删除失败");
      this.$message({ type: "success", message: "删除成功" });
      this.getData();
    },
    pageChange(page) {
      this.pageNum = page;
      this.getData();
    },
  },
};
</script>